package gui.tools;

import gui.ColorChooser;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import tools.vetorial.VectorialRectTool;

public class VectorialRecToolSetup extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private ColorChooser mColorChooser = new ColorChooser();
	
	private ColorChooser mHachuraColor = new ColorChooser();
	
	private JTextField mTxt = new JTextField();
	
	private VectorialRectTool mRectTool;
	
	public VectorialRecToolSetup(VectorialRectTool tool){
		this.mRectTool = tool;
		
		init();
	}

	protected void init(){
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		//Seletor cor
		mColorChooser.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				mRectTool.setColor(mColorChooser.getSelectedColor());
			}
		});
		
		mColorChooser.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
		
		mHachuraColor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				mRectTool.setHachuraColor(mHachuraColor.getSelectedColor());
			}
		});
		
		mHachuraColor.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
	
		mTxt.getDocument().addDocumentListener(new DocumentListener() {
			
			@Override
			public void removeUpdate(DocumentEvent arg0) {
				changedUpdate(arg0);
			}
			
			@Override
			public void insertUpdate(DocumentEvent arg0) {
				changedUpdate(arg0);
			}
			
			@Override
			public void changedUpdate(DocumentEvent arg0) {
				try{
					mRectTool.setHachuraSize(Integer.parseInt(mTxt.getText()));
				}catch(NumberFormatException nfe) {
					
				}
			}
		});
		
		add(mColorChooser);
		add(mTxt);
		add(mHachuraColor);
	}

	
}
